package com.ay.weixin.fdc.boss.share.db;

import java.sql.SQLException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lizar.db.ibatis.Dao;

import com.ay.weixin.fdc.boss.share.domain.ShareActivity;

public class ShareActivityDao extends Dao {
	public List<ShareActivity> getByStatus(long wxproject_id,int status) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("wxproject_id",wxproject_id);
		map.put("status",status);
		return (List<ShareActivity>)this.sqlMapper.queryForList("share_activity.getByStatus",map);
	}
	
	public void insert(ShareActivity share) throws SQLException{
		this.sqlMapper.insert("share_activity.insert",share);
	}
	
	public void update(ShareActivity share) throws SQLException{
		this.sqlMapper.update("share_activity.update",share);
	}
	
	public List<ShareActivity> getAllTop50(long wxproject_id) throws SQLException{
		return (List<ShareActivity>)this.sqlMapper.queryForList("share_activity.getAllTop50",wxproject_id);
	}
	
	public void update_announcement(ShareActivity share) throws SQLException{
		this.sqlMapper.update("share_activity.update_announcement",share);
	}
	
	public void archive_now(long id) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("id",id);
		map.put("status",ShareActivity.STATUS.CLOSED.getValue());
		map.put("start",Calendar.getInstance().getTime());
		this.sqlMapper.update("share_activity.archive_now",map);
	}
	
	

	public void published(long id) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("id",id);
		map.put("status",ShareActivity.STATUS.PUBLISHED.getValue());
		this.sqlMapper.update("share_activity.published",map);
		
	}
	
	
	public void start(long id) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("id",id);
		map.put("status",ShareActivity.STATUS.ON_GOING.getValue());
		map.put("start",Calendar.getInstance().getTime());
		this.sqlMapper.update("share_activity.start",map);
		
	}
	
	public void delete(long id) throws SQLException{
		this.sqlMapper.delete("share_activity.delete",id);
	}
	
	
	public void stop(long id) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("id",id);
		map.put("status",ShareActivity.STATUS.END.getValue());
		map.put("start",Calendar.getInstance().getTime());
		this.sqlMapper.update("share_activity.stop",map);
		
	}
	
	public ShareActivity getById(long id) throws SQLException{
		return (ShareActivity)this.sqlMapper.queryForObject("share_activity.getById",id);
	}
}
